package com.ct.factory;

import com.ct.entity.po.AdvanceApproval;

import java.math.BigDecimal;
import java.util.Date;

public class AdvanceApprovalFactory {

    /**
     * 创建AdvanceApproval对象并初始化基础属性
     * 
     * @param financeId 财务人员ID
     * @param advanceId 预支申请ID
     * @param payment   支付金额（字符串格式）
     * @return 初始化后的AdvanceApproval实例
     */
    public static AdvanceApproval create(String financeId, Integer advanceId, String payment) {
        AdvanceApproval advanceApproval = new AdvanceApproval();
        advanceApproval.setFinanceId(financeId);
        advanceApproval.setAdvanceId(advanceId);

        // 处理支付金额（空值转换为0）
        if (payment != null && !payment.isEmpty()) {
            advanceApproval.setPayment(new BigDecimal(payment));
        } else {
            advanceApproval.setPayment(new BigDecimal(0));
        }

        // 设置当前时间
        advanceApproval.setDate(new Date(System.currentTimeMillis()));
        return advanceApproval;
    }
}